package 笔试.荣耀;

//参考lc68、文本左右对齐
import java.util.*;
public class Demo02 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String[] words = str.split(",");
        int maxWidth = in.nextInt();
        //存放每一行的结果
        List<String> res = new ArrayList<>();
        int index = 0;
        while (index < words.length) {
            int cur = index, len = 0;
            while (cur < words.length && len + words[cur].length() + cur - index <= maxWidth) {
                len += words[cur++].length();
            }
            cur--;
            StringBuilder sb = new StringBuilder();
            //最后一行
            if (cur == words.length - 1) {
                for (int i = index; i <= cur; i++) {
                    sb.append(words[i]);
                    if (i < cur) {
                        sb.append('*');
                    }
                }
            } else {  //非最后一行
                int base = cur > index ? (maxWidth - len) / (cur - index) : (maxWidth - len);
                String baseStr = genSpace(base);
                int left = cur > index ? (maxWidth - len) % (cur - index) : 0;
                String leftStr = genSpace(base + 1);
                for (int i = index; i <= cur; i++) {
                    sb.append(words[i]);
                    if (i < cur) {
                        sb.append(left > 0 ? leftStr : baseStr);
                        left--;
                    }
                }
            }
            if (sb.length() < maxWidth) {
                sb.append(genSpace(maxWidth - sb.length()));
            }
            res.add(sb.toString());
            index = cur + 1;
        }
        //输出结果
        for (String item : res) {
            System.out.println(item);
        }
        in.close();
    }

    public static String genSpace(int n){
        char[] cs = new char[n];
        Arrays.fill(cs,'*');
        return new String(cs);
    }

}

